<template>
	<view class="container" style="margin: 30rpx;">
		<form>
			<view class="input-row" style="padding-top: 30rpx;">
				<view style="width: 200rpx;">整改不通过意见：</view>
			</view>
			<view class="input-row" style="padding-top: 30rpx;">
				<textarea style="width: 500rpx;" type="text" v-model="deny_rs_level2" />
			</view>
			<view style="display: flex;align-items: center;text-align: center;">
				<button @click="submitForm"
					style="width: 500rpx;height: 80rpx;background-color: #00aaff;color: #fff;">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		request
	} from '@/request/index.js';
	export default {
		data() {
			return {
				deny_rs_level2: '',
				pid: '',
				cproject: '',
				pmode: '',
				presult: '',
				ptype:''
			};
		},
		onLoad(option) {
			var userInfo = uni.getStorageSync('user');
			// if (userInfo == null || userInfo == 'null' || userInfo == '') {
			// 	uni.showToast({
			// 		title: "请先登录",
			// 		success() {
			// 			uni.reLaunch({
			// 				url: "/pages/login/login"
			// 			})
			// 		}
			// 	})

			// }
			var _self = this;
			_self.userInfo = userInfo
		
			this.ptype = option.ptype
			this.pid = option.pid
			this.getCpatrol(option.pid)
		},
		methods: {

			updateDenyRsLevel2(pid) {

				if (this.deny_rs_level2 == "") {
					uni.showToast({
						title: "二级整改意见不能为空"
					})
					return;
				}

				var data = {}
				data.pid = pid
				data.deny_rs_level2 = this.deny_rs_level2
				data.cproject = this.cproject
				data.pmode = this.pmode
				data.presult = this.presult
				var uri = ""
				if (this.ptype == '01') {
					uri = "/thirdForm/doUpdate/c_cpatrol"
				}
				if (this.ptype == '02') {
					uri = "/thirdForm/doUpdate/c_spatrol"
				}
				if (this.ptype == '03') {
					uri = "/thirdForm/doUpdate/c_qpatrol"
				}
				request({
					url: uri,
					method: "POST",
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'cookie': uni.getStorageSync('cookie')
					}
				}).then(res => {
					if (res.data.success == true) {
						uni.showToast({
							title: '操作成功',

						})
						this.reject2(pid)
					} else {
						uni.showToast({
							title: res.data.msg,

						})
					}
				})
			},

			reject2(pid) {
				var data = {}
				data.pids = pid
				request({
					url: "/patrol2/limitRectifyDeny2",
					method: "POST",
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'cookie': uni.getStorageSync('cookie')
					}
				}).then(res => {
			
					if (res.data.success == true) {
						uni.showToast({
							title: '操作成功',

						})
						uni.redirectTo({
							url:"/pages/updateCpatrol/updateCpatrol?pid="+pid+"&ptype="+this.ptype
						})
					} else {
						uni.showToast({
							title: res.data.msg,

						})
					}
				})
			},
			getCpatrol(pid) {
				var data = {}
				data.query_pid = pid
				var uri = ""
				if (this.ptype == '01') {
					uri = "/thirdGrid/query/c_cpatrol-m_cpatrol"
				}
				if (this.ptype == '02') {
					uri = "/thirdGrid/query/c_spatrol-m_spatrol"
				}
				if (this.ptype == '03') {
					uri = "/thirdGrid/query/c_qpatrol-m_qpatrol"
				}
				request({
					url: uri,
					method: "POST",
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'cookie': uni.getStorageSync('cookie')
					}
				}).then(res => {
					
					if (res.data.success == true) {
						if (res.data.rows.length > 0) {
							this.cproject = res.data.rows[0].cproject_val
							this.pmode = res.data.rows[0].pmode_val
							this.presult = res.data.rows[0].presult_val
						}

					} else {
						uni.showToast({
							title: res.data.msg,

						})
					}
				})
			},
			submitForm() {
				this.updateDenyRsLevel2(this.pid)
			}
		}
	};
</script>

<style>
	.container {
		padding: 0px;
	}

	.input-row {
		margin-bottom: 20px;
		display: flex;

	}

	.input-row text {
		flex-grow: 1;
		margin-right: 10px;
	}
</style>